/**
 * 
 */
package co.edu.uniandes.mdd.project1.sample.view;

import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import co.edu.uniandes.mdd.project1.sample.domain.Player;

/**
 * @author Leonardo
 * 
 */
public class PanelScore extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel labelX;
	private JLabel textFieldX;
	private JLabel labelY;
	private JLabel textFieldY;
	private JLabel labelScore;
	private JLabel textScore;

	public PanelScore(Player player) {
		setBorder(new CompoundBorder(new EmptyBorder(0, 0, 5, 0),
				new TitledBorder("Estadisticas")));
		setLayout(new GridLayout(1, 6));

		labelX = new JLabel("X:");
		textFieldX = new JLabel("" + player.getPositionX());

		labelY = new JLabel("Y:");
		textFieldY = new JLabel("" + player.getPositionY());

		labelScore = new JLabel("Score:");
		textScore = new JLabel();

		add(labelX);
		add(textFieldX);
		add(labelY);
		add(textFieldY);
		add(labelScore);
		add(textScore);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable o, Object arg) {
		if (arg instanceof Player) {
			Player player = (Player) arg;
			textFieldX.setText(new Integer(player.getPositionX()).toString());
			textFieldY.setText(new Integer(player.getPositionY()).toString());
			textScore.setText(new Integer(player.getScore()).toString());
		}
		
	}

}
